package com.itheima.day09;

import java.util.Scanner;

public class testDemo6 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请选择你要计算的图形");
        System.out.println("0: 正方形 1: 长方形 2: 圆形");

        int num = sc.nextInt();
        switch (num){
            case 0:
                System.out.println("请输入正方形的边长:");

                Square sq = new Square(sc.nextInt());
                System.out.println("正方形的周长是" + sq.getPerimeter());
                System.out.println("正方形的面积是" + sq.getArea());
                break;
            case 1:
                System.out.println("请输入长方形的长和宽:");
                Rectangle re = new Rectangle(sc.nextInt(),sc.nextInt());
                System.out.println("长方形的周长是" + re.getPerimeter());
                System.out.println("长方形的面积是" + re.getArea());
                break;
            case 2:
                System.out.println("请输入圆的半径:");
                Round ro = new Round(sc.nextInt());
                System.out.println("圆的周长是" + ro.getPerimeter());
                System.out.println("圆的面积是" + ro.getArea());
                break;

            default:
                System.out.println("输入有误!");
        }
    }
}
class Square {
    private double side;
    public Square() {
    }
    public Square(double side) {
        this.side = side;
    }
    public double getSide() {
        return side;
    }

    public void setSide(double side) {
        this.side = side;
    }
    //1.3、提供获取周长和面积的方法
//定义获取周长的方法getPerimeter()，返回值double类型，不需参数，边长值从成员变量获取
    public double getPerimeter() {
        return side * 4;
    }
    //定义获取面积的方法getArea()，返回值double类型，不需参数，边长值从成员变量获取
    public double getArea() {
        return side * side;
    }
}
class Rectangle {
    private double width;
    private double height;
    public Rectangle() {
    }
    public Rectangle(double width, double height) {
        this.width = width;
        this.height = height;
    }
    public double getWidth() {
        return width;
    }
    public void setWidth(double width) {
        this.width = width;
    }
    public double getHeight() {
        return height;
    }
    public void setHeight(double height) {
        this.height = height;
    }
    //2.4、提供获取周长和面积的方法
//获取周长：周长 =（宽+高）*2；
    public double getPerimeter() {
        return (width + height) * 2;
    }
    //获取面积
    public double getArea() {
        return width * height;
    }
}
class Round {
    private double r;
    public Round() {
    }
    public Round(double r) {
        this.r = r;
    }
    public double getR() {
        return r;
    }
    public void setR(double r) {
        this.r = r;
    }
    //3.3、提供获取周长和面积的方法
//获取周长
    public double getPerimeter() {
        return 2 * 3.14 * r;
    }
//获取面积
    public double getArea() {
        return 3.14 * r * r;
    }
}